package cn.hl.hm.controller;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.hl.hm.constants.PayMethod;
import cn.hl.hm.handler.PayExecuteFactory;
import cn.hl.hm.handler.PayHandler;
/**
 * 
 * @author 大和
 *
 */
@Controller
@RequestMapping("/unionpayCallBackController")
public class UnionpayCallbackController {
	@RequestMapping(value = "/callback")
	public String callback(HttpServletRequest request, HttpServletResponse response) {
		try {
			PrintWriter writer = response.getWriter();
			PayHandler payHandler = PayExecuteFactory.findPayHandler(PayMethod.YL_PAY);
			Boolean result = payHandler.callback(request,response);
			if (result) {
				writer.write("sucess");
				writer.close();
				return null;
			} else {
				writer.write("failure");
				writer.close();
				return null;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			return null;
		}
	}
}
